clc
clear

L=1;
dx=0.02;

[x,y]=meshgrid(-L:dx:L,-L:dx:L);
n=size(x,1);
u = zeros(n,n);

u(x.^2+y.^2<0.5.^2)=1;

figure

for tick = 1:200
    for k = 1:200
        i = uint32(rand()*(n-3))+2;
        j = uint32(rand()*(n-3))+2;
        d = randi(4);

        if d == 1
            temp1 = u(i,j);
            temp2 = u(i+1,j);
            u(i+1,j) = temp1;
            u(i,j) = temp2;
        elseif d == 2
            temp1 = u(i,j);
            temp2 = u(i,j+1);
            u(i,j+1) = temp1;
            u(i,j) = temp2;
        elseif d == 3
            temp1 = u(i,j);
            temp2 = u(i-1,j);
            u(i-1,j) = temp1;
            u(i,j) = temp2;
        elseif d == 4
            temp1 = u(i,j);
            temp2 = u(i,j-1);
            u(i,j-1) = temp1;
            u(i,j) = temp2;
        end

    end

    clf
    hold on
    axis equal
    surf(x,y,u,'EdgeColor','None');
    drawnow
    pause(0.1)
    disp(sum(u(:)))
end


